"""
多场景比较
"""
from typing import List, Dict, Any
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from .model_factory import ModelFactory
from .prompt_templates import COMPARISON_PROMPT


class Comparator:
    """
    多场景比较类
    """
    def __init__(self, model_name: str = "chatgpt"):
        self.model = ModelFactory().get_model(model_name)
        self.chain = self._create_comparison_chain()
    
    def _create_comparison_chain(self) -> LLMChain:
        """
        创建比较链
        """
        prompt = PromptTemplate(
            input_variables=["scenes_data"],
            template=COMPARISON_PROMPT
        )
        return LLMChain(llm=self.model, prompt=prompt)
    
    def compare(self, scenes_data: List[Dict[str, Any]]) -> Dict[str, Any]:
        """
        比较多个场景
        
        Args:
            scenes_data: 场景数据列表
        """
        try:
            response = self.chain.run(
                scenes_data=scenes_data
            )
            return {
                "comparison": response,
                "best_scene": self._extract_best_scene(response),
                "improvement_suggestions": self._extract_suggestions(response)
            }
        except Exception as e:
            raise RuntimeError(f"场景比较失败: {str(e)}")
    
    def _extract_best_scene(self, comparison: str) -> str:
        """
        提取最佳场景
        """
        # TODO: 实现最佳场景提取逻辑
        return ""
    
    def _extract_suggestions(self, comparison: str) -> list:
        """
        提取改进建议
        """
        # TODO: 实现建议提取逻辑
        return []